list1 = [x for x in range(10)]
print(list1)

print('*' * 50)

list2 = [j for i in range(10) for j in range(i)]
# 往列表list2中添加j
# i=0: 不添加j
# i=1:  j:0
# i=2:  j:0 1
# i=3:  j:0 1 2
# ...............
# i=9:  j:0 1 2 3 4 5 6 7 8
# [0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8]
print(list2)

print('*' * 50)

# 生成二维数组
a = [[col * row for col in range(5)] for row in range(5)]
# 往列表a中添加 col*row
# col在内层，从0到4
# row=0:0 0 0 0 0
# row=1:0 1 2 3 4
# row=2:0 2 4 6 8
# row=3:0 3 6 9 12
# row=4:0 4 8 12 16
print(a)

print('*' * 50)

# 二维转一维
b = [j for x in a for j in x]
print(b)

print('*' * 50)

# 使用if
c = [x for x in range(10) if x % 2 == 0]
print(c)

print('*' * 50)


# 使用if_else
d = [x if x % 2 == 0 else x ** 2 for x in range(10)]
print(d)
